package com.hoperun.product.net;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.hoperun.product.Models.DaoshaModel;
import com.hoperun.product.Models.HuanBiModel;
import com.hoperun.product.Models.ZhenshaModel;
import com.hoperun.product.entity.ProductInputEntity;
import com.hoperun.product.entity.ProductQueryEntity;
import com.hoperun.product.entity.UserBean;
import com.hoperun.product.util.SharedPreUtil;

import android.os.Handler;

public class RequestServiceImpl {

	/**
	 * 登录请求
	 * 
	 * @param handler
	 * @param account  员工工号
	 * @param password  密码
	 */
	public static void login(Handler handler,int requestType, String account, String password,String bmmc) {

		JSONObject inputInfo = new JSONObject();

		try {
			inputInfo.put("gh", account);
			//inputInfo.put("YHKL", password);
			//inputInfo.put("BMMC", bmmc);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="LoginQuick";
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 换批登录请求
	 *
	 * @param handler
	 * @param account  员工工号
	 * @param password  密码
	 */
	public static void login_huanpi(Handler handler,int requestType, String account, String password) {

		JSONObject inputInfo = new JSONObject();

		try {
			inputInfo.put("YHM", account);
			inputInfo.put("YHKL", password);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="Login_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	public static void checktupdate(Handler handler,int requestType){
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("appname", "准备车间app");
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="XTSJ_GetPadInfo_M";
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 倒纱列表汇总页面
	 */
	public static void gettotaldaolist(Handler handler,int requestType, String JobDate,String bc,String gh,String zb,String gz,String discount,String creater,String crename) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("JobDate", JobDate);
			}
			if(bc.length()>0){
				inputInfo.put("bc", bc);
			}
			if(gh.length()>0){
				inputInfo.put("gh", gh);
			}
			if(zb.length()>0){
				inputInfo.put("zb", zb);
			}
			if(gz.length()>0){
				inputInfo.put("gz", gz);
			}

			inputInfo.put("creater", creater);
			inputInfo.put("crename", crename);

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCL_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}



	/**
	 * 根据日期获取列表 倒纱
	 */
	public static void getdatelist(Handler handler,int requestType, String datetime) {
		JSONObject inputInfo = new JSONObject();
		try {
			//inputInfo.put("jobDate", datetime);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_GetExistCount_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}



	/**
	 * 根据条件查询 倒纱
	 */
	public static void querydaolist(Handler handler,int requestType, String JobDate,String ph,String gh,String zb,String gz) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("JobDate", JobDate);
			}
			if(ph.length()>0){
				inputInfo.put("ph", ph);
			}
			if(gh.length()>0){
				inputInfo.put("gh", gh);
			}
			if(zb.length()>0){
				inputInfo.put("zb", zb);
			}
			if(gz.length()>0){
				inputInfo.put("gz", gz);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 * 获取工种
	 */
	public static void querygz(Handler handler,int requestType) {
		JSONObject inputInfo = new JSONObject();
		try {

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_GetGZList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 获取备注
	 */
	public static void querybeizhu(Handler handler,int requestType) {
		JSONObject inputInfo = new JSONObject();
		try {

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="RYMSHPD_QueryMainBZ_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 * 根据批号支别获取原料信息
	 */
	public static void getYuanliaoInfo(Handler handler,int requestType,String ph,String zb) {
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("ph", ph);
			inputInfo.put("zb", zb);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_GetYLListByPHZB_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 根据缸号取纱信息
	 */
	public static void getYuanliaoFromGaohao(Handler handler,int requestType,String ganghao) {
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("gh", ganghao);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_GetYLListByGH_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}



	/**
	 * 更新倒纱信息
	 */
	public static void updateDaosha(Handler handler,int requestType,List<DaoshaModel> productList) {
          String result="";
		try {
			Gson gson = new GsonBuilder().serializeNulls().create();
			result = gson.toJson(productList);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_Update_LR_M";

		IServiceImpl.callWebMethod(handler, requestType, result , methodName);
	}

	/**
	 * 更新换批
	 */
	public static void updatehuanpi(Handler handler,int requestType,String ZBATER,String XM,List<HuanBiModel> productList) {
		com.alibaba.fastjson.JSONArray jsonarray =new com.alibaba.fastjson.JSONArray();
		try {
           for(HuanBiModel huanBiModel:productList){
			   com.alibaba.fastjson.JSONObject oneobjec=new com.alibaba.fastjson.JSONObject();
			   oneobjec.put("ZBATER",ZBATER);
			   oneobjec.put("ZBNAME",XM);
			   oneobjec.put("PKID",huanBiModel.getPKID());
			   jsonarray.add(oneobjec);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="RYMSHPD_Update_LR_M";

		IServiceImpl.callWebMethod(handler, requestType, jsonarray , methodName);
	}


	/**
	 * 删除倒纱
	 */
	public static void deleteDaosha(Handler handler,int requestType,List<String> PKIDList,String jobnum,String jobname) {
		JSONObject inputInfo = new JSONObject();
		try {
			JSONArray jsonData=new JSONArray();
			for (int i = 0; i < PKIDList.size(); i++) {
				jsonData.put(PKIDList.get(i));
			}
			inputInfo.put("DeleteId",jsonData);
			inputInfo.put("Updater",jobnum);
			inputInfo.put("UpdName",jobname);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_Delete_LR_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 * 查询纱支信息是否有效
	 */
	public static void validshaok(Handler handler,int requestType,List<DaoshaModel> PKIDList) {
		JSONArray jsonData=new JSONArray();
		try {
			for (int i = 0; i < PKIDList.size(); i++) {
				JSONObject jsonObject=new JSONObject();
				jsonObject.put("SZQC",PKIDList.get(i).getSzqc());
				jsonObject.put("COTTYPE",PKIDList.get(i).getCottype());
				jsonData.put(jsonObject);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_CheckMaterial_M";

		IServiceImpl.callWebMethod(handler, requestType, jsonData , methodName);
	}



	/**
	 * 根据条件查询 蒸纱
	 */
	public static void queryzhenlist(Handler handler,int requestType, String JobDate,String ph,String zb,String gh) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("jobdate", JobDate);
			}
			if(ph.length()>0){//批号
				inputInfo.put("BATCHNO", ph);
			}
			if(zb.length()>0){//支别
				inputInfo.put("COTTYPE", zb);
			}
			if(gh.length()>0){
				inputInfo.put("jobnum", gh);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCLLR_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 根据条件查询 换批
	 */
	public static void queryhuanpilist(Handler handler,int requestType,String XTYHID, String JobDate,String JobDate2,String cd, String ph,String shazhi,String remark) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("LISTDATE_From", JobDate);
			}
			if(JobDate2.length()>0){
				inputInfo.put("LISTDATE_To", JobDate2);
			}
			if(cd.length()>0){//产地
				inputInfo.put("ORIPLACE", cd);
			}
			if(ph.length()>0){//
				inputInfo.put("BATCHNO", ph);
			}
			if(shazhi.length()>0){
				inputInfo.put("SZQC", shazhi);
			}

			if(remark.length()>0){
				inputInfo.put("REMARK", remark);
			}

			if(XTYHID.length()>0){
				inputInfo.put("XTYHID", XTYHID);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="RYMSHPD_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 * 更新蒸纱信息
	 */
	public static void updateZhensha(Handler handler,int requestType,List<ZhenshaModel> productList) {
		String result="";
		try {
			Gson gson = new GsonBuilder().serializeNulls().create();
			result = gson.toJson(productList);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCLLR_Update_M";

		IServiceImpl.callWebMethod(handler, requestType, result , methodName);
	}


	/**
	 * 删除蒸纱
	 */
	public static void deleteZhensha(Handler handler,int requestType,List<String> PKIDList,String jobnum,String jobname) {
		JSONObject inputInfo = new JSONObject();
		try {
			JSONArray jsonData=new JSONArray();
			for (int i = 0; i < PKIDList.size(); i++) {
				jsonData.put(PKIDList.get(i));
			}
			inputInfo.put("DeleteId",jsonData);
			inputInfo.put("Updater",jobnum);
			inputInfo.put("UpdName",jobname);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCLLR_Delete_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 * 根据车号获取蒸纱
	 */
	public static void getYuanliaoInfo_sha_chehao(Handler handler,int requestType,String che) {
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("ch", che);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCLLR_GetYLListByCH_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}



	/**
	 * 根据日用量获取蒸纱
	 */
	public static void getYuanliaoInfo_sha_riyongliang(Handler handler,int requestType,String dateliang) {
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("date", dateliang);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCLLR_GetYLListByRYL_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 * 根据批号支别
	 */
	public static void getYuanliaoInfo_sha_pihao(Handler handler,int requestType,String pi,String zb) {
		JSONObject inputInfo = new JSONObject();
		try {
			inputInfo.put("ph", pi);
			inputInfo.put("zb", zb);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="DSRCLLR_GetYLListByPHZB_M";
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}



	/**
	 * 蒸纱列表汇总
	 */
	public static void gettotalzhenlist(Handler handler,int requestType, String JobDate,String bc,String gh) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("jobdate", JobDate);
			}
			if(bc.length()>0){//班次
				inputInfo.put("proclass", bc);
			}
			if(gh.length()>0){
				inputInfo.put("jobnum", gh);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="ZSRCL_QueryMainList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

	/**
	 *剥纱汇总
	 */
	public static void gettotalbolist(Handler handler,int requestType, String JobDate,String gh) {
		JSONObject inputInfo = new JSONObject();
		try {
			if(JobDate.length()>0){
				inputInfo.put("jobDate", JobDate);
			}

			if(gh.length()>0){
				inputInfo.put("jobnum", gh);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="BSGL_QueryMainCollectList_M";

		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}

























	/**
	 * 获取下拉框列表
	 * @param handler
	 * @param requestType
	 * @param
	 */
	public static void selectDict (Handler handler,int requestType,String  tableNo){
		JSONObject inputInfo = new JSONObject();

		try {
			inputInfo.put("TABLE_NO", tableNo);
		
		} catch (Exception e) {
			
		}
		String methodName="selectDict" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	
	
	/**
	 * 	查询该工号当前日期已经保存的数据 
	 * @param handler
	 * @param requestType
	 * @param jobNum
	 * @param jobDate
	 * 2017年 12月2 日修改   新增C_FLAG=IPAD字段
	 */
	public static void getInputList(Handler handler, int requestType,String userBean,String jobNum,String jobDate,String bmmc,String machineNo) {

		JSONObject inputInfo = new JSONObject();

		try {
			JSONObject jsonObject=new JSONObject(userBean);
			inputInfo.put("userBean", jsonObject);
			
			inputInfo.put("JOB_NUM", jobNum);
			inputInfo.put("JOBDATE", jobDate);
			inputInfo.put("BMMC", bmmc);
			inputInfo.put("MACHINENO", machineNo);
			inputInfo.put("C_FLAG", "IPAD");
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="wagequerydataByNoandDate" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	
	/**
	 * 删除(工资产量录入)
	 * @param handler
	 * @param requestType
	 * @param userBean
	 * @param
	 */
	public static void deleteInputProduct(Handler handler, int requestType,String userBean	,List<String> PKIDList) {

		JSONObject inputInfo = new JSONObject();

		try {
			JSONObject jsonObject=new JSONObject(userBean);
			inputInfo.put("userBean", jsonObject);
			
			
			JSONArray jsonData=new JSONArray();
			
			for (int i = 0; i < PKIDList.size(); i++) {
				JSONObject PKIDObject=new JSONObject();
				PKIDObject.put("PKID", PKIDList.get(i));
				jsonData.put(PKIDObject);
			}
			
			inputInfo.put("jsonData", jsonData);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="wageYieldInputDelete" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	/**
	 * 根据三联单号（布票条码）带出数据
	 * @param handler
	 * @param barCode
	 */
	public static void getInput(Handler handler, int requestType,String barCode,String jobNum,String jobDate) {

		JSONObject inputInfo = new JSONObject();

		try {
			inputInfo.put("CLOTHTKTNO", barCode);
			inputInfo.put("JOB_NUM", jobNum);
			inputInfo.put("JOBDATE", jobDate);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="wageYieldInput" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	
	
//	
//	 JSONArray array = new JSONArray();
//     for (int i = 0; i < 3; i++)
//     {
//         JSONObject value = new JSONObject();
//         value.put("", "");
//         value.put("", "");
//         array.put(value);
//     }
//     bodyVaule.put("", array);
	
	
	
	
	
	/**
	 * 保存/修改(工资产量录入)
	 * @param handler
	 * @param
	 * @param userBean
	 * @param productList
	 */
	public static void saveInputlist(Handler handler,int requestType, String  userBean,List<ProductInputEntity> productList,String bmmc ) {

		JSONObject inputInfo = new JSONObject();

		try {
			JSONObject jsonObject=new JSONObject(userBean);
			inputInfo.put("userBean", jsonObject);
			
			Gson gson = new GsonBuilder().serializeNulls().create();  
	        String result = gson.toJson(productList);
	        JSONArray jsonArray=new JSONArray(result);
        
			inputInfo.put("jsonData", jsonArray);
			inputInfo.put("BMMC", bmmc);
			
		
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="wageYieldInputedit" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	
	
	
	

	/**
	 * 查询产量
	 * @param handler
	 * @param requestType
	 * @param jobDate 日期 格式为 yyyy-mm-dd
	 * @param machineNo 车号	
	 * @param jobNum 工号
	 * @param classes 班次
	 * @param standardQuota 标准定额
	 */
	public static void getQuerylist(Handler handler,int requestType,String  userBean, String  jobDate ,String bmmc,String machineNo,String jobNum,
			String classes,String standardQuota) {

		JSONObject inputInfo = new JSONObject();

		try {
			JSONObject jsonObject=new JSONObject(userBean);
			inputInfo.put("userBean", jsonObject);
			inputInfo.put("JOBDATE", jobDate);
			inputInfo.put("BMMC", bmmc);
			inputInfo.put("MACHINENO", machineNo);
			inputInfo.put("JOB_NUM", jobNum);
			inputInfo.put("CLASSES", classes);
			inputInfo.put("WBZDE", standardQuota);
			inputInfo.put("C_FLAG", "IPAD");
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="wageYieldInputtoList" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}
	
	
	
	
	/**
	 * 
	 * 保存修改当天数据
	 * @param handler
	 * @param requestType
	 * @param userBean
	 * @param productList
	 */
	public static void updateQuerylist(Handler handler,int requestType, String  userBean,List<ProductQueryEntity> productList ){
		JSONObject inputInfo = new JSONObject();

		try {
			JSONObject jsonObject=new JSONObject(userBean);
			inputInfo.put("userBean", jsonObject);
			
			Gson gson = new GsonBuilder().serializeNulls().create();  
	        String result = gson.toJson(productList);
	        JSONArray jsonArray=new JSONArray(result);
			inputInfo.put("jsonData", jsonArray);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="updateBydatenum" ;
		
		IServiceImpl.callWebMethod(handler, requestType, inputInfo , methodName);
	}


	/**
	 *
	 * 获取服务器时间
	 */
	public static void getserverTime(Handler handler,int requestType){
		JSONObject inputInfo = new JSONObject();
		try {

		} catch (Exception e) {
			// TODO: handle exception
		}
		String methodName="XTSJ_GetDataTime_M" ;

		IServiceImpl.callWebMethod(handler, requestType, "" , methodName);
	}
	
}
